<?php

namespace Admin\Controller;

use Think\Controller;
use Think\Exception;

class OrderController extends PublicController
{

    /*
    *
    * 构造函数，用于导入外部文件和公共方法
    */
    public function _initialize()
    {
        $this->order = M('Order');
        $this->order_product = M('Order_product');

        $order_status = array('10' => '待付款', '20' => '已付款', '30' => '待发货', '40' => '待收货', '50' => '交易完成', '52' => '申请退款', '53' => '拒绝退款', '54' => '退款成功');
        $this->assign('order_status', $order_status);
        $return_status = array('-1' => '拒接退款', '1' => '申请中', '2' => '已退款');
        $this->assign("return_status", $return_status);
    }

    // 导入订单
    function import()
    {
        if (IS_File) {
            if (!empty ($_FILES)) {
                $upload = new \Think\Upload();                      // 实例化上传类
                $upload->maxSize = 10485760000;                 // 设置附件上传大小
                $upload->exts = array('xls', 'xlsx');       // 设置附件上传类型
                $upload->rootPath = './Data/UploadFiles/'; // 设置附件上传根目录
                $upload->savePath = ''; // 设置附件上传（子）目录
                $info = $upload->uploadOne($_FILES['wuliu']);

                if (!$info) {
                    exit($upload->getError());
                }
                $exts = $info['ext'];
                $filename = $upload->rootPath . $info['savepath'] . $info['savename'];

                vendor("PHPExcel.PHPExcel");

                if ($exts == 'xls') {                                        // 如果excel文件后缀名为.xls，导入这个类
                    vendor("PHPExcel.Reader.Excel5");
                    $PHPReader = new \PHPExcel_Reader_Excel5();
                } else if ($exts == 'xlsx') {
                    vendor("PHPExcel.Reader.Excel2007");
                    $PHPReader = new \PHPExcel_Reader_Excel2007();
                }
                $PHPExcel = $PHPReader->load($filename);
                $currentSheet = $PHPExcel->getSheet(0);
                $allColumn = $currentSheet->getHighestColumn();   // 获取总列数
                $allRow = $currentSheet->getHighestRow();              // 获取总行数

                $key = [];
                for ($currentRow = 1; $currentRow <= $allRow; $currentRow++) {// 循环获取表中的数据，$currentRow表示当前行，从哪行开始读取数据，索引值从0开始
                    for ($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn++) {// 从哪列开始，A表示第一列
                        $address = $currentColumn . $currentRow;             // 数据坐标
                        $cellValue = $currentSheet->getCell($address)->getValue();
                        if ($cellValue == '快递名称') {
                            $key['name'] = $currentColumn;
                            continue;
                        } elseif ($cellValue == '订单编号') {
                            $key['order_sn'] = $currentColumn;
                            continue;
                        } else if ($cellValue == '运单号') {
                            $key['wuliudanhao'] = $currentColumn;
                            continue;
                        }

                        if ($currentColumn == $key['name']) {
                            $ExlData[$currentRow]['name'] = $cellValue;
                        } else if ($currentColumn == $key['order_sn']) {
                            $ExlData[$currentRow]['order_sn'] = $cellValue;
                        } else if ($currentColumn == $key['wuliudanhao']) {
                            $ExlData[$currentRow]['wuliudanhao'] = $cellValue;
                        }

                        if (!$cellValue) {
                            break;
                        }
                    }
                }

                // 更新订单物流数据
                $result = ['error' => [], 'success' => []];
                if (!empty($ExlData)) {
                    foreach ($ExlData as $row) {
                        $wuLiuName = 'other';
                        switch ($row['name']) {
                            case '中通快递':
                                $wuLiuName = 'zhongtong';
                                break;
                            case 'EMS快递':
                                $wuLiuName = 'ems';
                                break;
                            case '申通快递':
                                $wuLiuName = 'shentong';
                                break;
                            case '顺丰快递':
                                $wuLiuName = 'shunfeng';
                                break;
                            case '圆通快递':
                                $wuLiuName = 'yuantong';
                                break;
                            case '韵达电子':
                            case '韵达快递':
                                $wuLiuName = 'yunda';
                                break;
                            case '百世汇通快递':
                                $wuLiuName = 'huitong';
                                break;
                            case '天天快递':
                                $wuLiuName = 'tiantian';
                                break;
                        }
                        $queryResult = $this->order->where("order_sn='{$row['order_sn']}'")->save(['kuaidi_num' => $row['wuliudanhao'], 'kuaidi_name' => $row['name'], 'post' => $wuLiuName, 'status' => '40']);

                        if (!$queryResult) {
                            $result['error'][] = $row['order_sn'];
                        } else {
                            $result['success'][] = $row['order_sn'];
                        }
                    }
                }

                $string = '订单物流状态更新完成，成功' . count($result['success']) . '条，失败' . count($result['error']) . '条';
                if (count($result['error']) > 0) {
                    $string .= '，失败订单号：' . implode('，', $result['error']);
                }
                echo $string;
            }
        }
    }

    /**
     * 导出订单
     */
    public function export()
    {
        $where = 'del = 0';
        $pay_status = !empty($_GET['pay_status']) ? intval($_GET['pay_status']) : 0;
        if ($pay_status) {
            if ($pay_status < 10) {
                //小于10的为退款
                $where .= ' AND back=' . intval($pay_status);
            } else {
                //大于10的为正常订单
                $where .= ' AND status=' . intval($pay_status);
            }
        }

        $where .= !empty($_GET['start_time']) ? ' AND addtime >= ' . strtotime($_GET['start_time']) : ''; //开始时间
        $where .= !empty($_GET['end_time']) ? ' AND addtime <= ' . strtotime($_GET['end_time']) : ''; //截止时间
        $order_list = $this->order->where($where)->order('id asc')->field('id, order_sn, receiver, tel, address_xq, remark')->select();

        vendor("PHPExcel.PHPExcel");
        vendor("PHPExcel.PHPExcel.Writer.Excel5");
        $excelObject = new \PHPExcel();
        $excelObject->setActiveSheetIndex(0)
            ->setCellValue('A1', '订单编号')
            ->setCellValue('B1', '收件人')
            ->setCellValue('C1', '固话')
            ->setCellValue('D1', '手机')
            ->setCellValue('E1', '地址')
            ->setCellValue('F1', '发货信息')
            ->setCellValue('G1', '备注')
            ->setCellValue('H1', '代收金额')
            ->setCellValue('I1', '保价金额')
            ->setCellValue('J1', '业务类型');

        foreach ($order_list as $index => $row) {
            $products = $this->order_product->where('order_id=' . $row['id'])->field('name, num')->select();
            $productsInfo = '';
            foreach ($products as $product) {
                $productsInfo .= $product['name'] . 'x' . $product['num'] . ';';
            }
            $rowIndex = $index + 2;
            $excelObject->getActiveSheet()
                ->setCellValueExplicit('A' . $rowIndex, (string)$row['order_sn'])
                ->setCellValue('B' . $rowIndex, $row['receiver'])
                ->setCellValue('C' . $rowIndex, '')
                ->setCellValueExplicit('D' . $rowIndex, $row['tel'])
                ->setCellValue('E' . $rowIndex, $row['address_xq'])
                ->setCellValue('F' . $rowIndex, $productsInfo)
                ->setCellValue('G' . $rowIndex, $row['remark'])
                ->setCellValue('H' . $rowIndex, '')
                ->setCellValue('I' . $rowIndex, '')
                ->setCellValue('J' . $rowIndex, '');
        }

        $title = date('Y-m-d') . '订单列表';
        header('Content-Type: application/vnd.ms-excel');
        header('Content-Disposition: attachment;filename="' . $title . '.xls"');
        header('Cache-Control: max-age=0');
        header('Cache-Control: max-age=1');

        $objWriter = new \PHPExcel_Writer_Excel5($excelObject);
        $objWriter->save('php://output');
    }

    /*
    *
    * 获取、查询所有订单数据
    */
    public function index()
    {
        //搜索
        //获取商家id
        if (intval($_SESSION['admininfo']['qx']) != 4) {
            $shop_id = intval(M('adminuser')->where('id=' . intval($_SESSION['admininfo']['id']))->getField('shop_id'));
            if ($shop_id == 0) {
                $this->error('非法操作.');
            }
        } else {
            $shop_id = intval($_REQUEST['shop_id']);
        }

        $pay_type = trim($_REQUEST['pay_type']);//支付类型
        $pay_status = intval($_REQUEST['pay_status']); //订单状态
        $start_time = intval(strtotime($_REQUEST['start_time'])); //订单状态
        $end_time = intval(strtotime($_REQUEST['end_time'])); //订单状态
        //构建搜索条件
        $condition = array();
        $condition['del'] = 0;
        $where = '1=1 AND del=0';
        //根据支付类型搜索
        if ($pay_type) {
            $condition['type'] = $pay_type;
            $where .= ' AND type=' . $pay_type;
            //搜索内容输出
            $this->assign('pay_type', $pay_type);
        }
        //根据订单状态搜索
        if ($pay_status) {
            if ($pay_status < 10) {
                //小于10的为退款
                $condition['back'] = $pay_status;
                $where .= ' AND back=' . intval($pay_status);
            } else {
                //大于10的为正常订单
                $condition['status'] = $pay_status;
                $where .= ' AND status=' . intval($pay_status);
            }

            //搜索内容输出
            $this->assign('pay_status', $pay_status);
        }
        //根据下单时间搜索
        if ($start_time) {
            $condition['addtime'] = array('gt', $start_time);
            $where .= ' AND addtime>' . $start_time;
            //搜索内容输出
            $this->assign('start_time', date("Y-m-d", $start_time));
        }
        //根据下单时间搜索
        if ($end_time) {
            $condition['addtime'] = array('lt', $end_time);
            $where .= ' AND addtime<' . $end_time;
            //搜索内容输出
            $this->assign('end_time', date("Y-m-d", $end_time));
        }
        /*if ($start_time && $end_time) {
            $condition['addtime'] = array('eq','addtime>'.$start_time.' AND addtime<='.$end_time);
        }*/

        /*//分页
        $count   = $this->order->where($where)->count();// 查询满足要求的总记录数
        $Page    = new \Think\Page($count,25);// 实例化分页类 传入总记录数和每页显示的记录数(25)

        //分页跳转的时候保证查询条件
        foreach($condition as $key=>$val) {
            $Page->parameter[$key]  =  urlencode($val);
        }*/
        /*if ($start_time && $end_time) {
            $addtime = 'addtime>'.$start_time.' AND addtime<'.$end_time;
            $Page->parameter['addtime']  =  urlencode($addtime);
        }*/

        /*//头部描述信息，默认值 “共 %TOTAL_ROW% 条记录”
        $Page->setConfig('header', '<li class="rows">共<b>%TOTAL_ROW%</b>条&nbsp;第<b>%NOW_PAGE%</b>页/共<b>%TOTAL_PAGE%</b>页</li>');
        //上一页描述信息
        $Page->setConfig('prev', '上一页');
        //下一页描述信息
        $Page->setConfig('next', '下一页');
        //首页描述信息
        $Page->setConfig('first', '首页');
        //末页描述信息
        $Page->setConfig('last', '末页');
        $Page->setConfig('theme', '%FIRST%%UP_PAGE%%LINK_PAGE%%DOWN_PAGE%%END%%HEADER%');

        $show    = $Page->show();// 分页显示输出*/
        define('rows', 15);
        $count = $this->order->where($where)->count();
        $rows = ceil($count / rows);
        $page = (int)$_GET['page'];
        $page < 0 ? $page = 0 : '';
        $limit = $page * rows;
        $page_index = $this->page_index($count, $rows, $page);
        // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
        $order_list = $this->order->where($where)->order('id desc')->limit($limit, rows)->select();
        foreach ($order_list as $k => $v) {
            $order_list[$k]['u_name'] = M('user')->where('id=' . intval($v['uid']))->getField('name');
        }
        //echo $where;
        $this->assign('order_list', $order_list);// 赋值数据集
        $this->assign('page_index', $page_index);// 赋值分页输出
        $this->assign('admin_qx', $_SESSION['admininfo']['qx']);//后台用户权限，目前设置为超级管理员权限
        $this->display(); // 输出模板

    }

    /*
    *
    * 选择商家里面的省市联动
    */
    public function get_city()
    {
        $id = (int)$_GET['id'];

        $data = M('china_city')->where('tid=' . intval($id))->field('id,name')->select();
        $i = 0;
        $array = array();
        foreach ($data as $v) {
            $array[$i]['id'] = $v['id'];
            $array[$i]['name'] = $v['name'];
            $i += 1;
        }
        echo json_encode($array);
    }


    /*
    *
    * 查看订单详情
    */
    public function show()
    {
        //获取传递过来的id
        $order_id = intval($_GET['oid']);
        if (!$order_id) {
            $this->error('系统错误.');
        }

        //根据订单id获取订单数据还有商品信息
        $order_info = $this->order->where('id=' . intval($order_id))->find();
        $order_info['name'] = M("user")->where('id=' . $order_info['uid'])->getField("name");
        $order_info['user_tel'] = M("user")->where('id=' . $order_info['uid'])->getField("tel");
        $order_info['addtime'] = date("Y-m-d H:i:s", $order_info['addtime']);
        $order_pro = $this->order_product->where('order_id=' . intval($order_id))->select();
        if (!$order_info || !$order_pro) {
            $this->error('订单信息错误.');
        }
        //获取物流
        $wuliu = $this->getLogistics();
        $this->assign("wuliu", $wuliu);
        foreach ($order_pro as $k => $v) {
            $data = array();
            $data = unserialize($v['pro_guide']);
            if ($data) {
                $order_pro[$k]['g_name'] = $data['gname'];
            } else {
                $order_pro[$k]['g_name'] = '无';
            }
        }
        $post_info = array();
        if (intval($order_info['post'])) {
            $post_info = M('post')->where('id=' . intval($order_info['post']))->find();
        }

        $this->assign('post_info', $post_info);
        $this->assign('order_info', $order_info);
        $this->assign('order_pro', $order_pro);
        $this->display();
    }


    /*
    *
    * 修改订单状态，添加物流名称、物流单号
    */
    public function sms_up()
    {
        $oid = intval($_POST['oid']);
        $o_info = $this->order->where('id=' . intval($oid))->find();
        if (!$o_info) {
            $arr = array('returns' => 0, 'message' => '没有找到相关订单.');
            echo json_encode($arr);
            exit();
        }

        //接收ajax传过来的值
        $kuaidi_name = $_POST['kuaidi_name'];
        $kuaidi_num = $_POST['kuaidi_num'];
        if ($o_info['kuaidi_name'] == $kuaidi_name && $o_info['kuaidi_num'] == $kuaidi_num) {
            $arr = array();
            $arr = array('returns' => 0, 'message' => '修改信息未发生变化.');
            echo json_encode($arr);
            exit();
        }

        try {
            if ($kuaidi_name == '' || $kuaidi_num == '') throw new Exception('参数不正确');
            //修改快递信息
            $data = array();
            $name = $this->getWuliuName($kuaidi_name);
            $data['kuaidi_name'] = $name;
            $data['post'] = $kuaidi_name;
            $data['status'] = 40;
            $data['kuaidi_num'] = $kuaidi_num;

            $up = $this->order->where('id=' . intval($oid))->save($data);
            $json = array();
            if ($up) {
                $json['message'] = "操作成功.";
                $json['returns'] = 1;
            } else {
                $json['message'] = "操作失败.";
                $json['returns'] = 0;
            }
        } catch (Exception $e) {
            $json = array('returns' => 0, 'message' => $e->getMessage());
        }

        echo json_encode($json);
        exit();
    }


    /*
    *
    *  确认退款  修改退款状态
    */
    public function back()
    {
        $id = (int)$_GET['oid'];
        $back_info = $this->order->where('id=' . intval($id))->find();
        if (!$back_info || intval($back_info['back']) != 1) {
            $this->error('订单信息错误.');
        }

        $data = array();
        $data['back'] = 2;

        $up_back = $this->order->where('id=' . intval($id))->save($data);
        if ($up_back) {
            $this->success('操作成功.');
        } else {
            $this->error('操作失败.');
        }
    }

    /*
    *
    *  订单删除方法
    */
    public function del()
    {
        //以后删除还要加权限登录判断
        $id = intval($_GET['did']);
        $check_info = $this->order->where('id=' . intval($id))->find();
        if (!$check_info) {
            $this->error('系统错误，请稍后再试.');
        }

        $up = array();
        $up['del'] = 1;
        $res = $this->order->where('id=' . intval($id))->save($up);
        if ($res) {
            $this->success('操作成功.');
        } else {
            $this->error('操作失败.');
        }
    }


    /*
    *
    *  订单统计功能
    */
    public function order_count()
    {
        //查询类型 d日视图  m月视图
        $type = $_GET['type'];
        //查询商家id
        $where = '1=1';

        //获取商家id
        if (intval($_SESSION['admininfo']['qx']) != 4) {
            $shop_id = intval(M('adminuser')->where('id=' . intval($_SESSION['admininfo']['id']))->getField('shop_id'));
            if ($shop_id == 0) {
                $this->error('非法操作.');
            }
        } else {
            $shop_id = intval($_REQUEST['shop_id']);
        }

        if ($shop_id) {
            $where .= ' AND shop_id=' . intval($shop_id);
            $shop_name = M('shangchang')->where('id=' . intval($shop_id))->getField('name');
            $this->assign('shop_name', $shop_name);
            $this->assign('shop_id', $shop_id);
        }

        for ($i = 0; $i < 12; $i++) {
            //日期
            if ($type == 'm') {
                $day = strtotime(date('Y-m')) - 86400 * 30 * (11 - $i);
                $dayend = $day + 86400 * 30;
                $day_String .= ',"' . date('Y/m', $day) . '"';
            } else {
                $day = strtotime(date('Y-m-d')) - 86400 * (11 - $i);
                $dayend = $day + 86400;
                $day_String .= ',"' . date('m/d', $day) . '"';
            }

            //$hyxl=select('id','aaa_pts_order',"1 $where and addtime>$day and addtime<$dayend",'num');
            $hyxl = $this->order->where($where . ' AND addtime>' . $day . " AND addtime<" . $dayend)->count('id');
            $data1 .= ',[' . $i . ',' . $hyxl . ']';
        }
        $this->assign('data1', $data1);
        $this->assign('day_String', $day_String);
        //当天日期的时间戳
        $today = strtotime(date('Y-m-d'));
        $this->assign('today', $today);

        //获取最近订单数据
        $order_list = $this->order->where($where)->order('id desc')->limit('0,20')->select();
        foreach ($order_list as $k => $v) {
            $order_list[$k]['shop_name'] = M('shangchang')->where('id=' . $v['shop_id'])->getField('name');
        }
        $this->assign('order_list', $order_list);
        $this->assign('type', $type);
        //print_r($where);die();
        $this->display();
    }

    /**
     * 售后服务列表
     */
    public function returnList()
    {

        $pay_status = intval($_REQUEST['pay_status']); //订单状态
        $start_time = intval(strtotime($_REQUEST['start_time'])); //订单状态
        $end_time = intval(strtotime($_REQUEST['end_time'])); //订单状态
        //构建搜索条件
        $condition = array();
        $where = '1=1 ';
        //根据订单状态搜索
        if ($pay_status) {
            $condition['status'] = $pay_status;
            $where .= ' AND status=' . intval($pay_status);
            //搜索内容输出
            $this->assign('pay_status', $pay_status);
        }
        //根据下单时间搜索
        if ($start_time) {
            $condition['addtime'] = array('gt', $start_time);
            $where .= ' AND addtime>' . $start_time;
            //搜索内容输出
            $this->assign('start_time', date("Y-m-d", $start_time));
        }
        //根据下单时间搜索
        if ($end_time) {
            $condition['addtime'] = array('lt', $end_time);
            $where .= ' AND addtime<' . $end_time;
            //搜索内容输出
            $this->assign('end_time', date("Y-m-d", $end_time));
        }
        define('rows', 15);
        $count = M("return_order")->where($where)->count();
        $rows = ceil($count / rows);
        $page = (int)$_GET['page'];
        $page < 0 ? $page = 0 : '';
        $limit = $page * rows;
        $page_index = $this->page_index($count, $rows, $page);
        $order_list = M("return_order")->where($where)->order('id desc')->limit($limit, rows)->select();
        foreach ($order_list as $k => $v) {
            $order_list[$k]['u_name'] = M('user')->where('id=' . intval($v['user_id']))->getField('name');
        }
        //echo $where;
        $this->assign('order_list', $order_list);// 赋值数据集
        $this->assign('page', $page_index);// 赋值分页输出
        $this->assign('admin_qx', $_SESSION['admininfo']['qx']);//后台用户权限，目前设置为超级管理员权限
        $this->display();
    }


    public function returnDetail()
    {
        //获取传递过来的id
        $id = intval($_GET['oid']);
        if (!$id) {
            $this->error('系统错误.');
        }
        $returnOrder = M("return_order")->where("id=" . $id)->find();
        $imgs = explode(",", $returnOrder['imgs']);
        $returnOrder['imgs'] = $imgs;
        $returnOrder['u_name'] = M('user')->where('id=' . intval($returnOrder['user_id']))->getField('name');
        $returnOrder['tel'] = M('user')->where('id=' . intval($returnOrder['user_id']))->getField('tel');
        $orderProductList = M("order_product")->where('order_id=' . $returnOrder['order_id'])->select();
        $order_info = M("order")->where('id=' . $returnOrder['order_id'])->find();
        $returnOrder['tel'] = $returnOrder['tel'] ? $returnOrder['tel'] : $order_info['tel'];
        $this->assign("order_pro", $orderProductList);
        $this->assign("order_info", $order_info);
        $this->assign("returnOrder", $returnOrder);
        $this->display();

    }

    /**
     * 平台同意不同意操作
     * @author tiedong
     * @date 2018-01-27
     */
    public function operateOrder()
    {
        $id = intval($_POST['id']);
        if (empty($id)) {
            $this->error("参数错误！");
            exit;
        }
        $type = intval($_POST['type']);
        switch ($type) {
            case "0" :
                $this->redirect('returnForm', array('id' => $id));
                break;
            case "1":
                $this->redirect('returnMenoy', array('id' => $id));
                break;
            default:
                echo "暂无数据";
                break;
        }
    }

    /**
     * 用户退款审核不通过提交原因接口
     * @author tiedong
     * @date 2018-01-29
     */
    public function returnForm()
    {
        $id = !empty($_GET['id']) ? intval($_GET['id']) : 0;
        if (IS_POST) {
            $pid = intval($_POST['id']);
            $returnOrder = M("return_order")->where("id=" . $pid)->find();
            $data['status'] = 53;
            $data['back'] = -1;
            M("order")->where('id=' . $returnOrder['order_id'])->setField($data);
            $data1['refund_mark'] = htmlentities($_POST['refund_mark']);
            $data1['status'] = -1;
            $result = M("return_order")->where('id=' . $pid)->setField($data1);
            if ($result) {
                $this->success('操作成功！', U('returnList'));
                exit;
            } else {
                $this->error('操作失败！', U('returnList'));
                exit;
            }

        } else {
            $this->assign("id", $id);
            $this->display();
        }
    }

    /**
     * 用户退款审核退款通过操作
     * @author tiedong
     * @date 2018-01-29
     */
    public function returnMenoy()
    {
        vendor('WeiXinpay.wxpay');
        $id = !empty($_GET['id']) ? intval($_GET['id']) : 0;
        if (empty($id)) {
            $this->error("参数有误！！");
            exit;
        }

        $returnOrder = M("return_order")->where("id=" . $id)->find();
        $order = M("order")->where('id=' . $returnOrder['order_id'])->find();
        $status = array("53", "54");
        if (is_array($order['status'], $status)) {
            $this->error("该订单不符合退款！");
            exit;
        }
        $orderId = M("order")->where("order_sn='{$order['order_sn']}'")->getField("id");
        if (empty($orderId)) {
            $this->error("该订单不能退款！");
            exit;
        }
        $trade_no = $order['trade_no'];
        $amoutPrice = D("order")->getSum($trade_no);
        $transaction_id = $trade_no;
        $total_fee = $amoutPrice * 100;
        $refund_fee = $returnOrder['refund_money'] * 100;
        $getConfig = C("weixin");
        try {
            $input = new \WxPayRefund();
            $input->SetTransaction_id($transaction_id);
            $input->SetTotal_fee($total_fee);
            $input->SetRefund_fee($refund_fee);
            $input->SetOut_refund_no($getConfig['mchid'] . date("YmdHis"));
            $input->SetOp_user_id($getConfig['mchid']);
            $result = \WxPayApi::refund($input);
            if (($result['return_code'] == 'SUCCESS') && ($result['result_code'] == 'SUCCESS')) {
                $data['status'] = 54;
                $data['back'] = 2;
                M("order")->where("id=" . $returnOrder['order_id'])->setField($data);
                $result = M("return_order")->where("id=" . $id)->setField("status", "2");
                if ($result) {
                    $this->success("退款成功！", U("returnList"));
                    exit;
                }
            }
        } catch (Exception $e) {
            var_dump($e->getMessage());
        }
    }

    public function getLogistics()
    {
        $wuliu = C("WULIU");
        $wuliu_arr = array();
        foreach ($wuliu as $key => $value) {
            $wuliu_arr[$key] = $value[0];
        }
        // var_dump($wuliu_arr);
        return $wuliu_arr;
    }

    public function getWuliuName($code)
    {
        $wuliu = C("WULIU");
        foreach ($wuliu as $key => $value) {
            if ($key == $code) {
                $name = $value['0'];
            }
        }
        return $name;
    }

    /**
     * 查看物流信息
     * @author tiedong
     * @date 2018-02-02
     */
    public function checkWuliu()
    {
        /*$code = !empty($_GET['code']) ? $_GET['code'] : null;
        if ( empty($code) ) {
            $this->error("该订单没有");
            exit;
        }*/
        include_once __DOCUMENT__ . "/extend/kuaidi/kuaidi100.php";
        $mm = !empty($_GET['nu']) ? $_GET['nu'] : null;
        $code = !empty($_GET['code']) ? $_GET['code'] : null;
        $ff = new \Kuaidi100();
        $data = $ff->kuaiDiInfo($code, $mm);
        $this->assign("list", $data);
        $this->display();
    }
}